﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace _2抽象类
{
    /// <summary>
    /// abstract抽象类和方法的标示
    /// </summary>
    abstract class Animal
    {
        protected string name = "";

        public Animal(string name)
        {
            this.name = name;
        }

        public Animal()
        {
            this.name = "无名";
        }

        protected int shoutNum = 3;

        public int ShoutNum
        {
            get { return shoutNum; }
            set { shoutNum = value; }
        }

        public string Shout()
        {
            string result = "";
            for (int i = 0; i < shoutNum; i++)
            {
                result += GetShoutSound() + ",";
            }

            return "我的名字叫" + name + " " + result;
        }
        /// <summary>
        /// abstract抽象方法
        /// </summary>
        /// <returns></returns>
        protected abstract string GetShoutSound();
    }

    class Cat : Animal
    {
        public Cat() : base()
        {
        }

        public Cat(string name) : base(name)
        {
        }

        protected override string GetShoutSound()
        {
            return "喵";
        }
    }

    class Dog : Animal
    {
        public Dog() : base()
        {
        }

        public Dog(string name) : base(name)
        {
        }

        protected override string GetShoutSound()
        {
            return "汪";
        }
    }

    class Cattle : Animal
    {
        public Cattle() : base()
        {
        }

        public Cattle(string name) : base(name)
        {
        }

        protected override string GetShoutSound()
        {
            return "哞";
        }
    }
    class Sheep : Animal
    {
        public Sheep() : base()
        {
        }
        public Sheep(string name) : base(name)
        {
        }
        protected override string GetShoutSound()
        {
            return "咩";
        }
    }
}
